<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绑定css样式</title>
    <!-- <script src="../vue.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        .happy{
            background-color: brown;
        }
        .sad{
            border: 1px green dashed;
            background-color: gray;
        }
        .normal{
            border: 1px blue solid;
            background-color: blue;
        }
        .basics{
            border: 1px black solid;
            height: 200px;
            width: 200px;
        }
        .style1{
           font-family: "微软雅黑";
           font-size: 20px;
        }
        .style2{
            box-shadow: 10px 10px 5px #888888;
        }
        .style3{
            border-radius: 5%;
        }
    </style>
</head>
<body>
    <div id="root">
        <!-- 绑定class样式---字符串写法，样式的类名不确定，需要动态指定 -->
        <div class="basics" :class="mood" @click="changebox">{{name}}</div><br/>
         <!-- 绑定class样式--数组写法，适用于：要绑定的个数不确定，名字也不确定 --> 
        <div class="basics" :class="classArr" >{{name}}</div><br/>
        <!-- 绑定class样式--对象写法，适用于：要绑定的个数确定，名字也确定，需要动态觉得 --> 
        <div class="basics" :class="classObj">{{name}}</div><br/><br/>

        <!-- 绑定style样式---对象写法 -->
        <div class="basics" :style="styleObj">{{name}}</div><br/><br/>
        
        <!-- 绑定style样式---对象数组常用写法 -->
        <div class="basics" :style="[styleObj,styleObj2]">{{name}}</div><br/><br/>
        <!-- 绑定style样式---对象数组不常用写法 -->
        <!-- <div class="basics" :style="styleArr">{{name}}</div><br/><br/> -->
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
    const vm = new Vue({
        el:'#root',
        data:{
            name:'内容',
            mood:'',
            classArr:['style1','style2','style3'],
            classObj:{
                style1:false,
                style2:false
            },
            styleObj:{
                fontSize: '40px',
                color:'red'
            },
            styleObj2:{
                backgroundColor: 'orange'
            },
            styleArr:[
                {
                    fontSize: '40px',
                    color:'red'
                },{
                    backgroundColor: 'blue'
                }
            ]
        },
        methods: {
            changebox(){
                let arr =['happy','sad','normal']
                ran = Math.random()*3
                index = Math.floor(ran)
                this.mood = arr[index]
            }
        },
    })
</script>
</html>